package com.yu.newsSys.controller;

import com.yu.newsSys.constants.NewsConstants;
import com.yu.newsSys.domain.News;
import com.yu.newsSys.service.NewsService;
import com.yu.newsSys.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/news")
public class NewsController {

    @Autowired
    private NewsService newsService;

    @RequestMapping("/getNews")
    @ResponseBody
    public Result getNews(@RequestParam(defaultValue = "1") int currentPage, String newsPaperName, String fileTitle) {
        Result news = newsService.getNews(newsPaperName, fileTitle, currentPage, NewsConstants.pageSize);
        System.out.println(news.getData());
        return newsService.getNews(newsPaperName, fileTitle, currentPage, NewsConstants.pageSize);
    }

    @RequestMapping("/add")
    @ResponseBody
    public Result add(News news) { // 表单方式提交的数据可直接通过一个对象接收
        return newsService.add(news);
    }
    @RequestMapping("/getNewsById")
    @ResponseBody
    public Result getNewsById(int id) {
        return newsService.getNewsById(id);
    }
    @RequestMapping("/edit")
    @ResponseBody
    public Result edit(News news) { // 表单方式提交的数据可直接通过一个对象接收
        return newsService.edit(news);
    }
    @RequestMapping("/remove/{id}")
    @ResponseBody
    public Result remove(@PathVariable int id) { // 表单方式提交的数据可直接通过一个对象接收
        return newsService.remove(id);
    }
}
